/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FavoritesDialog.java
 *
 * Created on Nov 25, 2009, 8:02:20 AM
 */
package com.bff.slimserver.musicjukebox.ui.components.favorites;

import com.bff.bjj.ui.component.BJJPanel;
import java.awt.Dimension;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bff.slimserver.musicobjects.favorite.SlimFavorite;

/**
 *
 * @author Bill
 */
public class FavoritesDialog extends javax.swing.JDialog {

    private SlimFavorite selectedFavorite;
    private boolean selected;

    /** Creates new form FavoritesDialog */
    public FavoritesDialog(java.awt.Frame parent) {
        super(parent, true);
        initComponents();
        setPreferredSize(new Dimension(300, 400));
        setMinimumSize(new Dimension(300, 400));
        try {
            getFavoriteTree().listAll();
        } catch (Exception ex) {
            Logger.getLogger(FavoritesDialog.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new BJJPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        favoritesTree = new FavoritesTree(false);
        jPanel2 = new BJJPanel();
        btnSelect = new javax.swing.JButton();
        btnCancel = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Select Favorite");

        jPanel1.setLayout(new java.awt.BorderLayout());

        jScrollPane1.setViewportView(favoritesTree);

        jPanel1.add(jScrollPane1, java.awt.BorderLayout.CENTER);

        getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);

        btnSelect.setText("Select");
        btnSelect.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSelectActionPerformed(evt);
            }
        });
        jPanel2.add(btnSelect);

        btnCancel.setText("Cancel");
        btnCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelActionPerformed(evt);
            }
        });
        jPanel2.add(btnCancel);

        getContentPane().add(jPanel2, java.awt.BorderLayout.SOUTH);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
        setSelected(false);
        dispose();
    }//GEN-LAST:event_btnCancelActionPerformed

    private void btnSelectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSelectActionPerformed
        setSelectedFavorite(getSelectedFavoriteFolder());
        setSelected(true);
        dispose();
    }//GEN-LAST:event_btnSelectActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancel;
    private javax.swing.JButton btnSelect;
    private javax.swing.JTree favoritesTree;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables

    private SlimFavorite getSelectedFavoriteFolder() {
        return getFavoriteTree().getSelectedFavorite();
    }

    private FavoritesTree getFavoriteTree() {
        return (FavoritesTree) favoritesTree;
    }

    /**
     * @return the selectedFavorite
     */
    public SlimFavorite getSelectedFavorite() {
        return selectedFavorite;
    }

    /**
     * @param selectedFavorite the selectedFavorite to set
     */
    private void setSelectedFavorite(SlimFavorite selectedFavorite) {
        this.selectedFavorite = selectedFavorite;
    }

    /**
     * @return the selected
     */
    public boolean isSelected() {
        return selected;
    }

    /**
     * @param selected the selected to set
     */
    public void setSelected(boolean selected) {
        this.selected = selected;
    }
}
